package com.example.demo_news.controller.admin;

import com.example.demo_news.service.Admin.AdminUserService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller
@PreAuthorize("hasAnyRole('admin')")
//只有管理员才能登录
public class AdminUserController {
    @Autowired
    private AdminUserService adminUserService;
    @RequestMapping("/adminUser")
    public String adminUser(Model model){
        if(adminUserService.findAllUser(model)){
            return "/admin/adminUser";
        }
        else return "/admin/adminIndex";
    }

    //删除用户
    @RequestMapping("/deleteUser")
    public String deleteUser(Integer id,Model model){
        if(adminUserService.deleteUser(id,model)){
            return "/admin/adminUser";
        }
        else return "/admin/adminIndex";
    }

    //修改用户权限
   @RequestMapping("/modifyRole")
   public String adminModifyRole(Integer id){
        if(adminUserService.modifyRole(id)){
            return "/admin/adminUser";
        }
        return "/admin/adminUser";
   }
}
